function [ error ] = Error_Perm( P_true, P )

[N,d] = size(P);
n = N/d;

errori = n;
for i = 1:n
    relative_Pi = P((i-1)*d+1:i*d,:)' * P_true((i-1)*d+1:i*d,:);
    errorj = n;
    for j = 1:n
        if P((j-1)*d+1:j*d,:) * relative_Pi == P_true((j-1)*d+1:j*d,:)
            errorj = errorj - 1;
        end
    end
    if errori > errorj
        errori = errorj;
    end
end
error = errori / n;
end